#!/usr/bin/env python
# -*- coding: UTF-8 -*-
"""
"""

# Echo client program
import socket
import sys

HOST = 'localhost'    # The remote host
PORT = 6500              # The same port as used by the server

s = None

try:
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
except socket.error, msg:
    s = None
    sys.exit(1)

try:
    s.connect((HOST, PORT))
except socket.error, msg:
    s.close()
    s = None

if s is None:
    print 'Cannot open socket'
    sys.exit(1)

data = raw_input('Input: ')
while 1:
    s.send(data)
    print 'send: ', data
    if data == 'quit':
        break
    data = s.recv(1024)
    print 'recv: ', repr(data)
    data = raw_input('Input: ')
    
s.close()
raw_input('Press any key to continue...')
